package com.insectstudio.haiivloffical;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.net.http.SslError;
import android.os.Bundle;
import android.view.Window;
import android.webkit.SslErrorHandler;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

public class ViewImageActivity extends Activity {
	
	private TextView txtTitle;
	private WebView wvViewImage;
	
	@SuppressLint("SetJavaScriptEnabled")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_view_image);
		// get references
		txtTitle = (TextView) findViewById(R.id.txt_title);
		wvViewImage = (WebView) findViewById(R.id.wv_view_image);
		// get extras
		String imageUrl = getIntent().getStringExtra("imageUrl");
		String title = getIntent().getStringExtra("title");
		// set data
		txtTitle.setText(title);
		// setting for web view
		wvViewImage.setWebChromeClient(new MyWebChromeClient());
		wvViewImage.setWebViewClient(new MyWebViewClient());
		wvViewImage.clearCache(true);
		wvViewImage.clearHistory();
		wvViewImage.getSettings().setJavaScriptEnabled(true);
		wvViewImage.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
		// load url
		wvViewImage.loadUrl(imageUrl);
	}
	
	class MyWebViewClient extends WebViewClient {
		
		@Override
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
			// TODO Auto-generated method stub
			view.loadUrl(url);
			return true;
		}

		@Override
		public void onPageFinished(WebView view, String url) {
			// TODO Auto-generated method stub
			super.onPageFinished(view, url);
		}
		
		@Override
		public void onReceivedSslError(WebView view, SslErrorHandler handler,
				SslError error) {
			// TODO Auto-generated method stub
//			super.onReceivedSslError(view, handler, error);
			handler.proceed();
		}
	}
	
	class MyWebChromeClient extends WebChromeClient {
		
	}

}
